package com.tcenter.dao.entities;


import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 */
@Entity
@Table(name = "course", catalog = "tcenterdb")
public class Course implements java.io.Serializable {

    private Integer id;
    private Lecturer lecturer;
    private String name;
    private Date startDate;
    private Date expirationDate;
    private Set<Subject> subjects = new HashSet<Subject>(0);
    private Set<Group> groups = new HashSet<Group>(0);


    public Course() {
    }

    public Course(String name, Lecturer lecturer) {
        this.lecturer = lecturer;
        this.name = name;
    }

    public Course(String name, Lecturer lecturer, Date startDate, Date expirationDate) {
        this.lecturer = lecturer;
        this.name = name;
        this.startDate = startDate;
        this.expirationDate = expirationDate;
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "head_id", nullable = false)
    public Lecturer getLecturer() {
        return this.lecturer;
    }

    public void setLecturer(Lecturer lecturer) {
        this.lecturer = lecturer;
    }

    @Column(name = "name", nullable = false, length = 15)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "start_date", length = 10)
    public Date getStartDate() {
        return this.startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "expiration_date", length = 10)
    public Date getExpirationDate() {
        return this.expirationDate;
    }

    public void setExpirationDate(Date expirationDate) {
        this.expirationDate = expirationDate;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "course")
    public Set<Subject> getSubjects() {
        return this.subjects;
    }

    public void setSubjects(Set<Subject> subjects) {
        this.subjects = subjects;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "course")
    public Set<Group> getGroups() {
        return this.groups;
    }

    public void setGroups(Set<Group> groups) {
        this.groups = groups;
    }

}
